# -------------------------------------------------------------------
#       -*- coding: utf-8 -*-
#   @Project    :   studentSystem
#   @File       :   loginfo.py
#   @Author     :   WANGYU
#   @Time       :   2021-09-14 11:01:55
#   @Software   :   PyCharm
#   @Desc       :   
# -------------------------------------------------------------------


import time


def shwo_info():
    print('输入提示数字，执行相应操作：0退出 1查看日志')


# 记录日志
def write_loginfo(username):
    with open('log.txt', 'a') as file:
        s = f'用户名{username},登陆时间：{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))}'
        file.write(s)
        file.write('\n')


# 读取日志
def read_loginfo():
    with open('log.txt', 'r') as file:
        while True:
            line = file.readline()
            if line == '':
                break
            else:
                print(line, end='')


if __name__ == '__main__':
    username = input('亲输入用户名：')
    pwd = input('请输入密码：')
    if 'admin' == username and 'admin' == pwd:
        print('登陆成功')
        write_loginfo(username)  # 记录日志
        shwo_info()  # 提示用户要执行操作
        num = int(input('输入操作数字：'))
        while True:
            if num == 0:
                print('退出成功')
                break
            elif num == 1:
                print('查看登录日志')
                read_loginfo()  # 读取日志
                num = int(input('输入操作数字:'))
            else:
                print('输入数字有误!')
                num = int(input('输入操作数字:'))
    else:
        print('用户名或密码错误!')
    '''
    print(time.time())  # 秒
    print(time.localtime(time.time()))
    print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())))

    '''
